package com.qwc.blog.common.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @author qiuwencong
 * @version V1.0
 * @ClassName: ThrowableUtil
 * @Date 2021/8/18 10:18
 */
public class ThrowableUtil {

    private ThrowableUtil() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 获取堆栈信息
     */
    public static String getStackTrace(Throwable throwable) {
        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw)) {
            throwable.printStackTrace(pw);
            return sw.toString();
        }
    }
}
